package com.example.flowableoa.service.Impl;


import com.example.flowableoa.factory.FlowServiceFactory;
import com.example.flowableoa.service.IFlowInstanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Slf4j
@Service
public class IFlowInstanceServiceImpl extends FlowServiceFactory implements IFlowInstanceService {


    @Override
    public void staterProcessInstanceById(String GongHao, Map<String, Object> variables, String assignee1, String fulibianhao) {
        //String userName = new WebUtils().loginUserName();
        // 绑定当前认证的账号  我们的认证系统如果使用的是 SpringSecurity的话，默认就会设置当前登录的账号
        identityService.setAuthenticatedUserId(GongHao);
        // 我们把当前认证的账号 绑定在流程变量中
        //variables.put("loginUser",userName);
        //启动了一个流程实例
        try {
            variables.put("assignee1",assignee1);
            variables.put("Fulibianhao",fulibianhao);
           // System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

            runtimeService.startProcessInstanceById("公司福利流程:1:06889b00-a8eb-11ed-b67c-8c8caad3480b",variables) ;

            // runtimeService.startProcessInstanceWithForm()
            log.info("流程启动成功:procDefId:{}");
        }catch (Exception e){
            e.printStackTrace();
            log.info("流程启动失败:procDefId:{}");
            System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

        }

    }

    @Override
    public void qidongqingjialiucheng(String GongHao, Map<String, Object> variables, String assignee1, String fulibianhao) {
        identityService.setAuthenticatedUserId(GongHao);

        try {
            variables.put("assignee1",assignee1);
            variables.put("Fulibianhao",fulibianhao);
            // System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

            runtimeService.startProcessInstanceById("公司请假流程:1:1f60b372-a8ed-11ed-911c-8c8caad3480b",variables) ;

            // runtimeService.startProcessInstanceWithForm()
            log.info("流程启动成功:procDefId:{}");
        }catch (Exception e){
            e.printStackTrace();
            log.info("流程启动失败:procDefId:{}");
//            System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

        }
    }

    @Override
    public void qidongYuSuanZhuiJia(String GongHao, Map<String, Object> variables, String assignee1, String fulibianhao) {
        identityService.setAuthenticatedUserId(GongHao);

        try {
            variables.put("assignee1",assignee1);
            variables.put("Fulibianhao",fulibianhao);
            // System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

            runtimeService.startProcessInstanceById("公司预算追加:1:5f38e976-a7c3-11ed-b7fb-8c8caad3480b",variables) ;

            // runtimeService.startProcessInstanceWithForm()
            log.info("流程启动成功:procDefId:{}");
        }catch (Exception e){
            e.printStackTrace();
            log.info("流程启动失败:procDefId:{}");
//            System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

        }

    }

    @Override
    public void qidongBuKaLiuCheng(String GongHao, Map<String, Object> variables, String assignee1, String fulibianhao) {
        identityService.setAuthenticatedUserId(GongHao);

        try {
            variables.put("assignee1",assignee1);
            variables.put("Fulibianhao",fulibianhao);
            // System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

            runtimeService.startProcessInstanceById("公司补卡流程:1:ebca073c-a8eb-11ed-b67c-8c8caad3480b",variables) ;

            // runtimeService.startProcessInstanceWithForm()
            log.info("流程启动成功:procDefId:{}");
        }catch (Exception e){
            e.printStackTrace();
            log.info("流程启动失败:procDefId:{}");

        }
    }

    @Override
    public void qidongGangweixuqiu(String GongHao, Map<String, Object> variables, String assignee1, String fulibianhao) {
        identityService.setAuthenticatedUserId(GongHao);

        try {
            variables.put("assignee1",assignee1);
            variables.put("Fulibianhao",fulibianhao);
            // System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

            runtimeService.startProcessInstanceById("公司岗位需求:1:5f4b1424-a8eb-11ed-b67c-8c8caad3480b",variables) ;

            // runtimeService.startProcessInstanceWithForm()
            log.info("流程启动成功:procDefId:{}");
        }catch (Exception e){
            e.printStackTrace();
            log.info("流程启动失败:procDefId:{}");

        }
    }

    @Override
    public void qidongDingDanLiuCheng(String GongHao, Map<String, Object> variables, String assignee1, String fulibianhao)
    {
        identityService.setAuthenticatedUserId(GongHao);

        try {
            variables.put("assignee1",assignee1);
            variables.put("Fulibianhao",fulibianhao);
            // System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

            runtimeService.startProcessInstanceById("公司订单流程:1:e77719e3-a847-11ed-bc16-8c8caad3480b",variables) ;

            // runtimeService.startProcessInstanceWithForm()
            log.info("流程启动成功:procDefId:{}");
        }catch (Exception e){
            e.printStackTrace();
            log.info("流程启动失败:procDefId:{}");

        }
    }

    @Override
    public void qidongZhuanZhengShenqing(String GongHao, Map<String, Object> variables, String assignee1, String fulibianhao) {
        identityService.setAuthenticatedUserId(GongHao);

        try {
            variables.put("assignee1",assignee1);
            variables.put("Fulibianhao",fulibianhao);
            // System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

            runtimeService.startProcessInstanceById("公司转正申请流程:1:24d3c620-a8ec-11ed-b67c-8c8caad3480b",variables) ;

            // runtimeService.startProcessInstanceWithForm()
            log.info("流程启动成功:procDefId:{}");
        }catch (Exception e){
            e.printStackTrace();
            log.info("流程启动失败:procDefId:{}");

        }
    }

    @Override
    public void qidongLiZhiShenQing(String GongHao, Map<String, Object> variables, String assignee1, String fulibianhao) {
        identityService.setAuthenticatedUserId(GongHao);

        try {
            variables.put("assignee1",assignee1);
            variables.put("Fulibianhao",fulibianhao);
            // System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

            runtimeService.startProcessInstanceById("公司离职申请流程:1:8f793738-a8eb-11ed-b67c-8c8caad3480b",variables) ;

            // runtimeService.startProcessInstanceWithForm()
            log.info("流程启动成功:procDefId:{}");
        }catch (Exception e){
            e.printStackTrace();
            log.info("流程启动失败:procDefId:{}");

        }
    }

    @Override
    public void qidongFeiYongBaoXiao(String GongHao, Map<String, Object> variables, String assignee1, String fulibianhao) {
        identityService.setAuthenticatedUserId(GongHao);

        try {
            variables.put("assignee1",assignee1);
            variables.put("Fulibianhao",fulibianhao);
            // System.err.println(GongHao+","+variables+","+assignee1+","+fulibianhao);

            runtimeService.startProcessInstanceById("公司费用报销流程:1:8a10da7c-a8e9-11ed-b616-8c8caad3480b",variables) ;

            // runtimeService.startProcessInstanceWithForm()
            log.info("流程启动成功:procDefId:{}");
        }catch (Exception e){
            e.printStackTrace();
            log.info("流程启动失败:procDefId:{}");

        }
    }
}
